
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public final class HttpTools {

    public static String getResponseFromUrl(String protocol, String domin, int port, String url) throws Exception {
        try {
            URL urlClass = new URL(protocol, domin, port, url);
            URLConnection urlConnect = urlClass.openConnection();
            urlConnect.setConnectTimeout(3000);
            urlConnect.setReadTimeout(10000);
            InputStream stream = urlConnect.getInputStream();
            byte buf[] = new byte[1000];
            int i, rtn = 0;
            for (i = 0; i < 1000; i++) {
                rtn = stream.read();
                if (rtn < 0)
                    break;
                buf[i] = (byte) rtn;
            }
            String output = new String(buf, 0, i);
            stream.close();
            return output.trim();
        }
        catch (Exception e) {
            throw new Exception(e);
        }
    }
}
